﻿/**  PACS v1.0
* JC_DepartInfo.cs
*
* 类 名： JC_DepartInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:28   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_DepartInfo
	/// </summary>
	public partial class JC_DepartInfo
	{
		public JC_DepartInfo()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from JC_DepartInfo");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_DepartInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.KeShiMing != null)
			{
				strSql1.Append("KeShiMing,");
				strSql2.Append("'"+model.KeShiMing+"',");
			}
			if (model.KeShiBianMa != null)
			{
				strSql1.Append("KeShiBianMa,");
				strSql2.Append("'"+model.KeShiBianMa+"',");
			}
			if (model.SuoShuJiGouID != null)
			{
				strSql1.Append("SuoShuJiGouID,");
				strSql2.Append("'"+model.SuoShuJiGouID+"',");
			}
			if (model.YingXiangKeBiaoShi != null)
			{
				strSql1.Append("YingXiangKeBiaoShi,");
				strSql2.Append("'"+model.YingXiangKeBiaoShi+"',");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql1.Append("JianChaLeiXing,");
				strSql2.Append("'"+model.JianChaLeiXing+"',");
			}
			if (model.SheBieID != null)
			{
				strSql1.Append("SheBieID,");
				strSql2.Append("'"+model.SheBieID+"',");
			}
			if (model.JianChaLeiXingID != null)
			{
				strSql1.Append("JianChaLeiXingID,");
				strSql2.Append("'"+model.JianChaLeiXingID+"',");
			}
			if (model.KeShiLeiBie != null)
			{
				strSql1.Append("KeShiLeiBie,");
				strSql2.Append("'"+model.KeShiLeiBie+"',");
			}
			if (model.BeiZhu != null)
			{
				strSql1.Append("BeiZhu,");
				strSql2.Append("'"+model.BeiZhu+"',");
			}
			strSql.Append("insert into JC_DepartInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_DepartInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_DepartInfo set ");
			if (model.KeShiMing != null)
			{
				strSql.Append("KeShiMing='"+model.KeShiMing+"',");
			}
			else
			{
				strSql.Append("KeShiMing= null ,");
			}
			if (model.KeShiBianMa != null)
			{
				strSql.Append("KeShiBianMa='"+model.KeShiBianMa+"',");
			}
			else
			{
				strSql.Append("KeShiBianMa= null ,");
			}
			if (model.SuoShuJiGouID != null)
			{
				strSql.Append("SuoShuJiGouID='"+model.SuoShuJiGouID+"',");
			}
			else
			{
				strSql.Append("SuoShuJiGouID= null ,");
			}
			if (model.YingXiangKeBiaoShi != null)
			{
				strSql.Append("YingXiangKeBiaoShi='"+model.YingXiangKeBiaoShi+"',");
			}
			else
			{
				strSql.Append("YingXiangKeBiaoShi= null ,");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql.Append("JianChaLeiXing='"+model.JianChaLeiXing+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXing= null ,");
			}
			if (model.SheBieID != null)
			{
				strSql.Append("SheBieID='"+model.SheBieID+"',");
			}
			else
			{
				strSql.Append("SheBieID= null ,");
			}
			if (model.JianChaLeiXingID != null)
			{
				strSql.Append("JianChaLeiXingID='"+model.JianChaLeiXingID+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXingID= null ,");
			}
			if (model.KeShiLeiBie != null)
			{
				strSql.Append("KeShiLeiBie='"+model.KeShiLeiBie+"',");
			}
			else
			{
				strSql.Append("KeShiLeiBie= null ,");
			}
			if (model.BeiZhu != null)
			{
				strSql.Append("BeiZhu='"+model.BeiZhu+"',");
			}
			else
			{
				strSql.Append("BeiZhu= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_DepartInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_DepartInfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_DepartInfo GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,KeShiMing,KeShiBianMa,SuoShuJiGouID,YingXiangKeBiaoShi,JianChaLeiXing,SheBieID,JianChaLeiXingID,KeShiLeiBie,BeiZhu ");
			strSql.Append(" from JC_DepartInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.JC_DepartInfo model=new Pacs.Model.JC_DepartInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_DepartInfo DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_DepartInfo model=new Pacs.Model.JC_DepartInfo();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["KeShiMing"]!=null)
				{
					model.KeShiMing=row["KeShiMing"].ToString();
				}
				if(row["KeShiBianMa"]!=null)
				{
					model.KeShiBianMa=row["KeShiBianMa"].ToString();
				}
				if(row["SuoShuJiGouID"]!=null)
				{
					model.SuoShuJiGouID=row["SuoShuJiGouID"].ToString();
				}
				if(row["YingXiangKeBiaoShi"]!=null)
				{
					model.YingXiangKeBiaoShi=row["YingXiangKeBiaoShi"].ToString();
				}
				if(row["JianChaLeiXing"]!=null)
				{
					model.JianChaLeiXing=row["JianChaLeiXing"].ToString();
				}
				if(row["SheBieID"]!=null)
				{
					model.SheBieID=row["SheBieID"].ToString();
				}
				if(row["JianChaLeiXingID"]!=null)
				{
					model.JianChaLeiXingID=row["JianChaLeiXingID"].ToString();
				}
				if(row["KeShiLeiBie"]!=null)
				{
					model.KeShiLeiBie=row["KeShiLeiBie"].ToString();
				}
				if(row["BeiZhu"]!=null)
				{
					model.BeiZhu=row["BeiZhu"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,KeShiMing,KeShiBianMa,SuoShuJiGouID,YingXiangKeBiaoShi,JianChaLeiXing,SheBieID,JianChaLeiXingID,KeShiLeiBie,BeiZhu ");
			strSql.Append(" FROM JC_DepartInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,KeShiMing,KeShiBianMa,SuoShuJiGouID,YingXiangKeBiaoShi,JianChaLeiXing,SheBieID,JianChaLeiXingID,KeShiLeiBie,BeiZhu ");
			strSql.Append(" FROM JC_DepartInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_DepartInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_DepartInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

